home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
tex
/
toadso11.zip
/
TOADSO11.ASM
< prev
next >
Wrap
Assembly Source File
|
1986-01-15
|
27KB
|
1,011 lines
Page 82,132
Title TOADSOFT - Convert text file to or from WordStar format
Comment | Version 1.1, 15 Jan 86
TOADSOFT Command
-----------------
Purpose: 1. Convert text file to WordStar .DOC format
or convert WordStar .DOC formatted file to text file.
2. Replace blanks with tab character(s)
or expand tabs.
Format: TOADSOFT [d:[input.ext]] [d:[output.ext]] [/t] [/u]
Remarks: Any tab characters found are first expanded. If TABS
appear within quoted strings - out of context - they will
not be expanded.
The default is to expand tabs (the normal WordStar DOC format).
- Carriage return/line feeds within a paragraph are "softened"
(Cr becomes 13 + 128) to permit WordStar reformatting.
- If 2 or more spaces in a row, the last space is "softened"
(Space becomes 32 + 128) to permit WordStar reformatting.
The /U option may be used to Unsoften a WordStar DOC file.
Tabs (if any) will automatically be expanded unless the
/T option is selected.
The /T option may be used to replace spaces with tabs, and may
be used without Unsoftening a W* DOC file.
Both /T and /U may be used together.
Side Effects: If a normal text file is Unsoftened and tabs
expanded ('/TU'), non-space characters may be followed by up
to 3 new spaces (where there used to be a nice neat tab).
This is an artifact of the minispace .. NO tab will be inserted
until 3 or more spaces have been used. Sorry 'bout that.
The maximum logical record size is 255, see MAXREC equate.
Defacto tab columns are 9,17,25,...
Credits:
- Majority of file handling and tab processing from
Vernon Buerg's TABS version 1.6gg, 10 Jul 85.
- Ensoft procedure from ENSOFT2.C (yep, translated back from C)
by Gordon Brandley (original author)
totally rewritten by Harvey G. Lord.
Should run on any MS-DOS system with DOS 2.0 or higher.
For public domain use.
Author: David Kirschbaum, Toad Hall
7573 Jennings Lane
Fayetteville NC 28303
(919) 868-3471
ARPAnet ABN.ISCAMS@USC-ISID
Notes:
I do some baaaad things in here .. like not always entering and
leaving procedures at the same place, or beginning and end (tch tch).
But .. I wanted it tight and fast .. and I wrote it for ME to
understand, not necessarily for you. It always traces logically ..
you'll just have to work at it.
Toad Hall
v1.1, 15 Jan 86: ENSOFT2.C specifies a leading space will turn off the
soft carriage return function for that line. I don't like that because
it makes reformatting columnar or indented material much harder (all the
hard cr/lfs are still there). Commented that test out.
Tried softening trailing hyphens (when ensoftening), but too much hassle.
Still one wee little bug .. can't seem to terminate the target file with
a clean Cr/Lf and Ctrl-Z .. always get a couple of spaces or tabs stuffed
in there. Strange.
[Toad Hall]
----------------- |
CSeg Segment Public Para 'CODE'
Assume CS:Cseg,DS:Cseg,ES:CSeg
Org 100h
Tabs Proc Far
Push DS ;DOS convention
Sub AX,AX
Push AX
Mov CS:Stk_Top,SP ;Save stack ptr to insure return
Call ChkVer ;Check for DOS 2
Call Alloc ;Get maximum I/O buffers
Call GetFile ;Get file names
Call OpenIn ;Open input
Call OpenOut ; and output
Call Inform ;Display "cooking" message
Call GenTab ;Generate tabs
Call Flush ;Empty the output buffer
mov BX,Tabcnt ;get final tab count
call Print_count ;one last time
Mov DX,Offset EofMsg ;Say END-OF-FILE
Error: Mov SP,Stk_Top ;Insure proper return
Call PrintS ;Print any message
Call Close ;Close files
Ret ;Return to DOS
Page
Buflen Dw 0 ;I/O buffer size
MinCore Dw 512 ;Minimum of one sector
Maxrec Equ 255 ;Longest logical record
S_Quote Equ 34 ;Single quote
D_Quote Equ 39 ;Double quote
Tab Equ 9
Lf Equ 10
Cr Equ 13
EOF Equ 1AH
FormF Equ 0CH
Soft_Cr Equ 8DH ;W* soft carriage return
End_Hyph Equ 1FH ;W* soft hyphen at end of line
Mid_Hyph Equ 1EH ;W* soft hyphen NOT at end of line
Minspace equ 3 ;minimum # sequential spaces
; before a tab (adjust to your
; liking or circumstances).
;(No, I DON'T know what'll happen
; if you make it 0.)
Tabcnt Dw 0 ;tab counter
Rec Db Maxrec Dup (0) ;Current record
Sw Db 0 ;Number of blanks skipped
Qsw Db 0 ;Quote switch
Tabflg db 0 ;non-zero for tabbing function
Unsoft db 0 ;Non-zero for W* Unsoft
Lf_flag db 0 ;Lf counter for ensoft
space_flag db 0 ;space counter for ensoft
start_line db 0 ;new line flag for ensoft
Stk_Top Dw 0 ;SP at entry
MsgIn Db Cr,Lf,'Enter INPUT file name- ',255
Msg1 Db Cr,Lf,'Input failed to open, '
InKey Db 32,32 ;Keyboard buffer
Input Db 76 Dup (0),0,255 ;Drive:path\name.ext
IHandle Dw 0 ;Input file handle
Ilen Dw 0 ;Input block length
Iptr Dw 0 ;Offset to next char
In_Ptr Dw 0 ;Seg offset
MsgOut Db Cr,Lf,'Enter OUTPUT file name- ',255
Msg2 Db Cr,Lf,'Output failed to open, '
OutKey Db 32,32
Output Db 76 Dup (0),0,255
OHandle Dw 0 ;Output file handle
Olen Dw 0 ;Bytes in output buffer
Optr Dw 0 ;Offset to next char
Out_Ptr Dw 0 ;Seg offset
DTA Db 48 Dup (0)
Page
Sorry Db Cr,Lf,'Sorry, DOS Version 2 required',Cr,Lf,255
Msg3f Db Cr,Lf,'I/O error reading',Cr,Lf,255
Msg40 Db Cr,Lf,'I/O error writing',Cr,Lf,255
Msg4a Db Cr,Lf,'Insufficient memory',Cr,Lf,255
Msg4e Db Cr,Lf,'No matching file(s) found',Cr,Lf,255
InformD Db 'De-'
Cooking Db 'Tabbing, ',255
SoftStr db 'nsofting: ',255
Mark Db ' => ',255
EofMsg Db Cr,Lf,'End of File',Cr,Lf,255
Code2 Db 'File not found ',255
Code3 Db 'Path not found ',255
Code4 Db 'Too many files ',255
Code5 Db 'Access denied ',255
CmdLine db 'TOADSOFT Version 1.1, Toad Hall, 15 Jan 86, public domain',cr,lf
db 'Command:',cr,lf
db 'TOADSOFT [d:][\p\][ source.typ][ target.typ] [/t][/u][/tu]',cr,lf
db 'where source is file to be changed,',cr,lf
db ' target is destination file (names MUST be different)',cr,lf
db 'and options t = tabify (change spaces to tabs),',cr,lf
db ' u = unsoften (change W* file to ASCII).',cr,lf
db 'Defaults are Ensoften and expand tabs to spaces.',cr,lf,255
;
; Replace blanks with tabs
GenTab Proc Near
Loop: Call GetRec ;Get a record, length in CX
Sub BX,BX ;Output column
Mov Sw,BL ;No blanks yet
Mov Qsw,BL ;No quotes yet
Or CX,CX ;Any data in record?
jnz Set1 ;yep
jmp Null ; no, just CR-LF
;stuffed this in here cause the jumps were getting too long...
Done: cmp Lf_flag,0 ;still owe a cr/lf?
jz Done1 ; nope
call DoHarCrLf ;save a cr/lf
Done1: mov AL,Eof
jmp PutChar ;save that CtrlZ and return
Set1: Mov SI,Offset Rec ;Look for blanks and
Wloop: Lodsb ; replace strings of blanks
Cmp AL,EOF ;End of file?
Je Done ; yes, all done
Inc BX ; with tab characters
cmp Tabflg,255 ;are we tabifying? If not, we don't
; have any spaces saved anyway.
jne Copy ; nope, just save the char
; Don't count blanks within single or double quoted strings
Cmp AL,D_Quote ;Double quote?
Jne Chk1 ; nope, go check single
Xor Qsw,2 ; turn on/off the 2-bit for "
Jmp Chk2
Chk1: Cmp AL,S_Quote ;single quote?
jne Chk2 ; nope
cmp Rec[SI+1],'t' ;a n't?
je Copy ; yep, just skip it
Xor Qsw,1 ; turn on/off the 1-bit for '
Chk2: test Qsw,3 ;within quotes?
Jnz Insert ; yep, save them
;--- done with quotations
;our column counter is in BL.
Chk3: cmp BL,08H ;no tabs till col 9
jle Insert ;...and Insert'll take care of any
; leading spaces
mov AH,BL ;(not using AH for anything)
;this gets weird, but it's Boolean... and it works...
dec AH ; (don't ask...)
test AH,07H ;ready for a tab?
jnz Insert ; nope, see if we must insert
; skipped spaces.
;we have a character, and we're on a tab column.
;we'll only tab if we have Minspace spaces before this char.
Check: cmp Sw,Minspace ;minimum space?
jl Insert ; not enough spaces, gotta insert
call Test_Count